using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;

namespace NodeCanvas
{
	public static class NCReflection
	{
		private static List<Assembly> loadedAssemblies;

		private static IEnumerable GetBaseTypes(Type type)
		{
			yield return type;
			Type baseType = type.BaseType;
			if (baseType == null)
			{
				yield break;
			}
			IEnumerator enumerator = GetBaseTypes(baseType).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					yield return enumerator.Current;
				}
			}
			finally
			{
				IDisposable disposable;
				IDisposable disposable2 = (disposable = enumerator as IDisposable);
				if (disposable != null)
				{
					disposable2.Dispose();
				}
			}
		}

		public static bool NCIsAssignableFrom(this Type type, Type second)
		{
			return type.IsAssignableFrom(second);
		}

		public static bool NCIsAbstract(this Type type)
		{
			return type.IsAbstract;
		}

		public static bool NCIsInterface(this Type type)
		{
			return type.IsInterface;
		}

		public static FieldInfo NCGetField(this Type type, string name)
		{
			return type.GetField(name, BindingFlags.Instance | BindingFlags.Public);
		}

		public static PropertyInfo NCGetProperty(this Type type, string name)
		{
			return type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public);
		}

		public static MethodInfo NCGetMethod(this Type type, string name, bool includePrivate = false)
		{
			if (includePrivate)
			{
				return type.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			return type.GetMethod(name, BindingFlags.Instance | BindingFlags.Public);
		}

		public static MethodInfo NCGetMethod(this Type type, string name, Type[] paramTypes)
		{
			return type.GetMethod(name, paramTypes);
		}

		public static EventInfo NCGetEvent(this Type type, string name)
		{
			return type.GetEvent(name, BindingFlags.Instance | BindingFlags.Public);
		}

		public static FieldInfo[] NCGetFields(this Type type)
		{
			return type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}

		public static Attribute NCGetAttribute(this Type type, Type attType, bool inherited)
		{
			return type.GetCustomAttributes(attType, inherited).FirstOrDefault() as Attribute;
		}

		public static Type[] NCGetGenericArguments(this Type type)
		{
			return type.GetGenericArguments();
		}

		public static Type[] NCGetEmptyTypes()
		{
			return Type.EmptyTypes;
		}

		public static Delegate NCCreateDelegate(Type type, object arg, MethodInfo methodInfo)
		{
			return Delegate.CreateDelegate(type, arg, methodInfo);
		}

		public static List<Type> GetAssemblyTypes()
		{
			List<Type> list = new List<Type>();
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					list.AddRange(assembly.GetTypes());
				}
				catch
				{
					Debug.Log(assembly.FullName + " will be excluded");
				}
			}
			return list;
		}
	}
}
